using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using MySql.Data.MySqlClient;

namespace Calendar
{
    public partial class frmTaskDetail : Form
    {
        DataTable dtTasks;
        int i4dtTasks=0;
        DateTime dt;

        public frmTaskDetail(DateTime dt)
        {
            InitializeComponent();
            this.dt = dt;
        }

        public frmTaskDetail()
        {
            InitializeComponent();
        }

        private void frmTaskDetail_Load(object sender, EventArgs e)
        {
            //MessageBox.Show(dt.ToShortDateString().ToString());

            MySqlConnection con = new MySqlConnection("server=localhost;database=smartPM;uid=root;"); //burhan_smartmanager   password=abcdaaa
            con.Open();
            string qry = "select * from vwtask2 where startdate='" + dt.ToString("yyyy-MM-dd") + "' or estimatedEndDate='" + dt.ToString("yyyy-MM-dd") + "'"; // where ( startdate between '" + d.ToShortDateString() + "' and '" + d2.ToShortDateString() + "' ) or  ( estimatedEndDate between '" + d.ToShortDateString() + "' and '" + d2.ToShortDateString() + "' ) ";
            MySqlCommand cmd = new MySqlCommand(qry);
            cmd.Connection = con;
            MySqlDataAdapter da = new MySqlDataAdapter(cmd);
            dtTasks = new DataTable();
            da.Fill(dtTasks);
            con.Close();

            grpTask.Text = "Showing 1 of " + dtTasks.Rows.Count + " Task(s)";
            //btnPrevious.Enabled = false; btnNext.Enabled = false;
            //if (dtTasks.Rows.Count > 1) btnNext.Enabled = true;

            ShowTaskDetail();
        }

        private void btnPrevious_Click(object sender, EventArgs e)
        {
            if (i4dtTasks > 0) { i4dtTasks--; }
            ShowTaskDetail();
            grpTask.Text = "Showing " + (i4dtTasks+1) + " of " + dtTasks.Rows.Count + " Task(s)";
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            if (i4dtTasks < dtTasks.Rows.Count - 1) { i4dtTasks++; } //btnPrevious.Enabled = true; 
            ShowTaskDetail();
            grpTask.Text = "Showing " + (i4dtTasks + 1) + " of " + dtTasks.Rows.Count + " Task(s)";
        }

        private void ShowTaskDetail()
        {
            txtPrj.Text = dtTasks.Rows[i4dtTasks]["projectname"].ToString();
            txtMilestone.Text = dtTasks.Rows[i4dtTasks]["milestone"].ToString();
            txtPM.Text = dtTasks.Rows[i4dtTasks]["ProjectManager"].ToString();
            txtSummary.Text = dtTasks.Rows[i4dtTasks]["ShortSummary"].ToString();
            txtDesc.Text = dtTasks.Rows[i4dtTasks]["Description"].ToString();
            txtStartDate.Text = dtTasks.Rows[i4dtTasks]["startdate"].ToString();
            txtEndDate.Text = dtTasks.Rows[i4dtTasks]["estimatedEndDate"].ToString();
            txtAssignTo.Text = dtTasks.Rows[i4dtTasks]["AssignedTo"].ToString();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}